package com.more.offer.algorithm.leetcode.lcode20;

import java.util.Stack;

/**
 * @author pinoc
 * @date 2021/8/14
 * @description 牛逼的方法
 */
public class Solution2 {
	public static void main(String[] args) {
		Solution2 solution2 = new Solution2();
		boolean b = solution2.isValid("((([{}])))");
		System.out.println(b);
	}

	public boolean isValid(String str) {
		Stack<Character> stack = new Stack<>();
		for(char c : str.toCharArray()) {
			if(c == '(') {
				stack.push(')');
			} else if (c == '{'){
				stack.push('}');
			} else if (c =='['){
				stack.push(']');
			} else if(stack.isEmpty() || stack.pop() != c){
				return  false;
			}
		}
		return stack.isEmpty();
	}
}
